<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../css/reset.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/add.css"/>
    <link rel="stylesheet" href="../../assets/css/layui.css">
    <link rel="stylesheet" href="../../assets/css/view.css"/>
    <script src="/qrcode/jquery2.1.4.js"></script>
    <script src="/layer/layer.js"></script>
</head>
<body>
<div class="layui-content">
    <div class="layui-row">
        <div class="layui-card">
            <div class="layui-card-header">添加快递员</div>
            <form id="form1" class="layui-form layui-card-body">

                <div class="layui-form-item">
                    <label class="layui-form-label">姓名</label>
                    <div class="layui-input-block">
                        <input type="text" id="sysname" name="code" required lay-verify="required"
                               placeholder="请输入快递员姓名"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">电话</label>
                    <div class="layui-input-block">
                        <input type="text" id="sysphone" name="username" required lay-verify="required"
                               placeholder="请输入电话" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">身份证号码</label>
                    <div class="layui-input-block">
                        <input type="text" id="cardid" name="phonenumber" required lay-verify="required"
                               placeholder="请输入身份证号码" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">密码</label>
                    <div class="layui-input-block">
                        <input type="text" id="password" name="phonenumber" required lay-verify="required"
                               placeholder="请输入密码" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-blue" lay-submit lay-filter="formDemo">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>


<!--
<div id="app">
    <div class="header">
        <span>添加快递员</span>
    </div>
    <div class="content">

            <table>
                <tr>
                    <td class="text-right">姓名</td>
                    <td class="content_right"><input id="sysname" class="input" placeholder="请输入姓名"></td>
                </tr>
                <tr>
                    <td class="text-right">手机号码</td>
                    <td class="content_right"><input id="sysphone" class="input" placeholder="请输入手机号码"></td>
                </tr>
                <tr>
                    <td class="text-right">身份证号码</td>
                    <td class="content_right"><input id="cardid" class="input" placeholder="请输入身份证号码"></td>
                </tr>
                <tr>
                    <td class="text-right">密码</td>
                    <td class="content_right"><input id="password" class="input" placeholder="请输入密码"></td>
                </tr>
                <tr>
                    <td></td>
                    <td class="content_right">
                        <span id="form1"  class="btn btn-info">立即提交</span> <span class="btn">重置</span>
                    </td>
                </tr>
            </table>


        &lt;!&ndash;<span id="form1"  class="btn btn-info">立即提交</span> <span class="btn">重置</span>&ndash;&gt;

    </div>
</div>
-->


<script>

    function isName() {
        var sysname = $("input:eq(0)").val();
        if (sysname == "") {
            layer.tips("姓名不能为空", "#sysname", {tipsMore: true, tips: 1});
            return false;
        } else if (/^[\u4E00-\u9FA5A-Za-z0-9_]+$/.test(sysname) == false) {      //英文，中文，数字，下划线
            layer.tips("姓名只支持英文、中文、数字和下划线", "#sysname", {tipsMore: true, tips: 1});
            return false;
        }
        return true;
    }

    function isPhone() {
        var sysphone = $("input:eq(1)").val();
        if (sysphone == "") {
            layer.tips("电话不能为空", "#sysphone", {tipsMore: true, tips: 1});
            return false;
        } else if (/^^1[0-9]{10}$$/.test(sysphone) == false) {      //英文，中文，数字，下划线
            layer.tips("电话格式不合法", "#sysphone", {tipsMore: true, tips: 1});
            return false;
        }
        return true;
    }


    function isCardId() {
        var cardid = $("input:eq(2)").val();
        if (cardid == "") {
            layer.tips("身份证号码不能为空", "#cardid", {tipsMore: true, tips: 1});
            return false;
        } else if (/^[1-9]\d{17}/.test(cardid) == false) {      //英文，中文，数字，下划线
            layer.tips("身份证格式不合法", "#cardid", {tipsMore: true, tips: 1});
            return false;
        }
        return true;
    }

    function isPassword() {
        var password = $("input:eq(3)").val();
        if (password == "") {
            layer.tips("密码不能为空", "#password", {tipsMore: true, tips: 1});
            return false;
        } else if (password.length < 6) {      //英文，中文，数字，下划线
            layer.tips("密码位数不能少于6位", "#password", {tipsMore: true, tips: 1});
            return false;
        }
        return true;
    }

</script>
<script>
    $(function () {
        $("input:eq(0)").blur(function () {
            isName();
        });

        $("input:eq(1)").blur(function () {
            isPhone();
        });

        $("input:eq(2)").blur(function () {
            isCardId();
        });

        $("input:eq(3)").blur(function () {
            isPassword();
        });


        $("#form1").submit(function () {
            var bool = isName() && isPhone() && isCardId() && isPassword();
            if (bool) {
                var windowId = layer.load();
                var sysName = $("input:eq(0)").val();
                var sysPhone = $("input:eq(1)").val();
                var cardId = $("input:eq(2)").val();
                var password = $("input:eq(3)").val();
                $.post("/courier/insert.do", {
                    sysName: sysName,
                    sysPhone: sysPhone,
                    cardId: cardId,
                    password: password
                }, function (data) {
                    layer.close(windowId);
                    layer.msg(data.result);
                    if (data.status == 0) {
                        //录入成功
                        $("input").val("");
                    } else {
                        //录入失败
                    }
                });

                return false;
            }
        });


    })
</script>

</body>
</html>
